const { DataTypes } = require('sequelize');
const sequelize = require('../config/database');

const DietRecord = sequelize.define('DietRecord', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  userId: {
    type: DataTypes.INTEGER,
    allowNull: false,
    references: {
      model: 'Users',
      key: 'id'
    }
  },
  date: {
    type: DataTypes.DATEONLY,
    allowNull: false
  },
  mealType: {
    type: DataTypes.ENUM('早餐', '午餐', '晚餐', '加餐'),
    allowNull: false
  },
  foods: {
    type: DataTypes.JSON,
    allowNull: false,
    defaultValue: []
  },
  totalCalories: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  totalProtein: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  totalCarbs: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  totalFat: {
    type: DataTypes.FLOAT,
    allowNull: false,
    defaultValue: 0
  },
  notes: {
    type: DataTypes.TEXT,
    allowNull: true
  },
  images: {
    type: DataTypes.JSON,
    allowNull: true,
    defaultValue: []
  }
});

module.exports = DietRecord; 